const red = document.querySelector('.red')
const green = document.querySelector('.green')
const yellow = document.querySelector('.yellow')

const openLight = (node) => node.classList.add('active')
const offLight = (node) => node.classList.remove('active')

function fn() {
  openLight(red)
  return new Promise((resolve) => {
    setTimeout(() => {
      offLight(red)
      resolve()
    }, 3000)
  })
    .then(() => {
      openLight(green)
      return new Promise((resolve) => {
        setTimeout(() => {
          offLight(green)
          resolve()
        }, 2000)
      })
    })
    .then(() => {
      openLight(yellow)
      return new Promise((resolve) => {
        setTimeout(() => {
          offLight(yellow)
          resolve(fn())
        }, 1000)
      })
    })
}
fn()
